<?php
/**
 * [WeEngine System] Copyright (c) 2013 WE7.CC
 * User: fanyk
 * Date: 2017/10/14
 * Time: 18:57
 */

namespace Ken\Wechat;


use Ken\Wechat\WechatApi;

class WechatStream {

	const WRAPPER_NAME = 'wechat';
	private $path = null;
	public static function register() {
		stream_register_wrapper(self::WRAPPER_NAME, get_class());
	}

	public function stream_open($path, $mode, $options, &$opened_path) {
		$this->path = $this->clearPrefix($path);
		return true;
	}

	public function stream_close() {

	}

	public function stream_write($data) {
		$api = new WechatApi();
		$api->put(__DIR__.'/no.jpg');
		return 10;
	}

	public function unlink($path) {

	}

	private function clearPrefix($path) {
		return str_replace(self::WRAPPER_NAME, '', $path);
	}
}